package com.reservation.service.impl;

import com.reservation.dto.admin.setting.ModifyMeetingRoomDTO;
import com.reservation.mapper.AdminSettingMapper;
import com.reservation.service.AdminSettingService;
import com.reservation.vo.admin.setting.AddMeetingRoomVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AdminSettingServiceImpl implements AdminSettingService {

    @Autowired
    private AdminSettingMapper adminSettingMapper;

    @Override
    public boolean addMeetingRoom(AddMeetingRoomVO addMeetingRoomVO) {

        String content = Arrays.stream(addMeetingRoomVO.getEquipment())
                .map(item -> "\"" + item + "\"")  // 每个元素加引号
                .collect(Collectors.joining(","));// 用逗号连接

        addMeetingRoomVO.setDescription("[" + content + "]");

        return adminSettingMapper.addMeetingRoom(addMeetingRoomVO) > 0 ;
    }

    @Override
    public boolean deleteMeetingRoom(int id) {

        return adminSettingMapper.setDeleteMeetingRoom(id) > 0 ;
    }

    @Override
    public boolean updateMeetingRoom(ModifyMeetingRoomDTO modifyMeetingRoomDTO) {
        modifyMeetingRoomDTO.setEquipmentSting(Arrays.toString(modifyMeetingRoomDTO.getEquipment()));
        return adminSettingMapper.setMeetingRoom(modifyMeetingRoomDTO) > 0 ;
    }
}
